#include "ball.h"
#include "sound.h"

Ball::Ball(const Vector2f& pos, const Vector2f& vel,const Frame* f):
Sprite(pos, vel, f){}


void Ball::update(unsigned ticks) { 
  float incr = velocityY() * static_cast<float>(ticks) * 0.001;
  Y( Y()+incr );
  //float height = static_cast<float>(frame->getHeight());
  if ( Y() < 0) {
    velocityY( abs( velocityY() ) );
    SDLSound::getInstance()->operator [](0);
  }	
  //if ( Y() > gameData->getXmlInt("worldHeight")-height) {
    //velocityY( -abs( velocityY() ) );
    //SDLSound::getInstance()->operator [](0);
  //}

  incr = velocityX() * static_cast<float>(ticks) * 0.001;
  X( X()+incr );
  float width = static_cast<float>(frame->getWidth());
  if ( X() < 0) {
    velocityX( abs( velocityX() ) );
    SDLSound::getInstance()->operator [](0);
  }
  if ( X() >  gameData->getXmlInt("worldWidth")-width) {
    velocityX( -abs( velocityX() ) );
    SDLSound::getInstance()->operator [](0);
  }
}

void Ball::draw() const {
	Sprite::draw();
}
